
    new Vue({
    el: '#app',
    data:{
    //给当前用户一个默认的未登录信息（防止报错）
    userInfo:{"data":{"id":"","username":"未登录123","":"","name":"","phone":"","sex":"","idNumber":"","avatar":"","status":""}},
    admin:{},   //用户信息

    radio: '1',



    //餐桌信息

    items:[
{
    id:'',
    image:'',
    isSchedule:'',
    name:'',
    description:'',
    price:'',
}
    ],

    //个人信息弹框
    drawer:false,
    login:false,
    logout:false,

    activeName:'',
    //个人预定过餐桌的信息表
    myScheduleTableFrom:{},

    //我的订单div
    myOrder:false,

    //订单
    options1:[{}],

    //修改个人信息弹框
    updateInformation:false,
    formData_user:{},
    imageUrl:'',
    //弹框表单（input）校验
    rules: {
    username: [
{ required: true, message: '请输入用户名', trigger: 'blur' },
{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
    ],
    name: [
{ required: true, message: '请输入姓名', trigger: 'blur' },
{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
    ],
    phone: [
{ required: true, message: '请输入手机号码', trigger: 'blur' },
{ min: 3, max: 11, message: '长度在 3 到 11 个字符', trigger: 'blur' }
    ],
    sex: [
{ required: true, message: '请选择性别', trigger: 'blur' },
    ],
    idNumber: [
{ required: true, message: '请输入省份证号', trigger: 'blur' },
{ min: 3, max:18, message: '长度在 3 到18 个字符', trigger: 'blur' }
    ],
},
},
    created() {
    const userInfo = window.localStorage.getItem('userInfo')
    console.log("dsdasdasdasd")
    if (userInfo!=="null") {
    if (JSON.parse(userInfo).data.username!=='未登录123'){
    this.userInfo = JSON.parse(userInfo)
}
}
    console.log("userInfo22:::")
    console.log(this.userInfo)

    this.getAll()
},
    methods: {

    getAll(){
    axios.get("/diningTables/getAllDiningTable").then((res)=> {
    console.log("获取全部餐桌数据：")
    console.log(res)
    console.log(res.data)
    this.items=res.data.data

    for (var i = 0; i < this.items.length; i++) {
    console.log(this.items[i].isSchedule)
    if (this.items[i].isSchedule=="是"){
    this.items[i].isFlag='已预定'
}else {
    this.items[i].isFlag='未预定'
}
}
})
},
    toMune(){
    window.location.href='menu.html'
},
    handleClose(done) {
    this.$confirm('确认关闭？')
    .then(_ => {
    done();
    this.getAll()
})
    .catch(_ => {});
},

    information(){
    this.drawer=true
    console.log(this.userInfo)
    if (this.userInfo.data.username!=="未登录123"){
    this.login=true
    this.logout=false
}else {
    this.logout=true
    this.login=false
}
},
    //退出登录
    logoutInformation(){
    this.$confirm('确认退出登录嘛？')
    .then(_ => {
    window.localStorage.removeItem('userInfo')
    this.drawer=false
    window.location.href="index.html"
    this.$message.success("账号已退出登录！");
})
    .catch(_ => {});
},

    //个人信息模块下的功能变化
    handleChange(){
    //修改个人信息（数据回显）
    if (this.activeName==1){
    this.updateInformation=true
    this.formData_user=this.userInfo.data
    this.imageUrl= `/photos/download?name=${this.userInfo.data.avatar}`

} else if (this.activeName==2){
    this.myOrder=true
    axios.get("/orders/getOrderById/"+this.userInfo.data.id).then((res)=>{
    console.log("查询当前用户的所有订单信息（包括详情）::")
    console.log(res.data.data)
    this.options1=res.data.data

})
}
    //查看个人预定餐桌的情况
    else if (this.activeName==4){
    axios.get("/scheduleTables/getAllByUserId/"+this.userInfo.data.id).then((res)=>{
    this.myScheduleTableFrom=res.data.data
})
}
},
    //取消预定餐桌
    centerSchedule(){
    this.$confirm("是否确认取消此预定，是否继续?","提醒",{type: 'info'
}).then(()=>{

    //删除预定表中的数据
    axios.delete("/scheduleTables/"+this.myScheduleTableFrom.id).then((res)=>{     //1.获取删除预定信息 然后将其状态设置为0
    this.$message.success(res.data.msg)

    //修改餐桌表是否被预定字段
    this.myScheduleTableFrom.isSchedule='否'
    axios.put("/diningTables/updateTableForIsSchedule",this.myScheduleTableFrom).then((res)=>{

})
}).finally(()=>{
    //手动让他为空，给界面展示已经取消预定还没预定餐桌的界面
        axios.get("/scheduleTables/getAllByUserId/"+this.userInfo.data.id).then((res)=>{
            this.myScheduleTableFrom=res.data.data
        })
    this.getAll()
})
}).catch(()=>{
    //取消删除
    this.$message.info("取消操作")
})
},
    //确认修改个人信息
    submitForm() {
    this.$refs.formData_user.validate((valid)=>{
    axios.put("/users",this.formData_user).then((res)=>{
    if (res.data.code){
    this.$message.success("修改个人信息成功！");
    localStorage.setItem('userInfo',JSON.stringify(res.data))
}
}).finally(()=>{
    this.getAll();
    this.updateInformation=false;
})
})
},
    //4.图片文件上传
    handleAvatarSuccess (response, file, fileList) {
    console.log("response:")
    console.log(response)
    this.formData_user.avatar=response.data

    this.imageUrl = `/photos/download?name=${response.data}`
},
    beforeUpload (file) {
    if(file){
    const suffix = file.name.split('.')[1]
    const size = file.size / 1024 / 1024 < 2
    if(['png','jpeg','jpg'].indexOf(suffix) < 0){
    this.$message.error('上传图片只支持 png、jpeg、jpg 格式！')
    this.$refs.upload.clearFiles()
    return false
}
    if(!size){
    this.$message.error('上传文件大小不能超过 2MB!')
    return false
}
    return file
}
}

}

})
